const { task } = require("hardhat/config")


// 部署合约 这个脚本就是直接封装，不过要把合约的地址打印出来，以便测试合约的时候可以让fundmeFactory.attach(taskArgs.addr) 拿到这个fundme对象
task("deploy-fundme", "deploy and verify fundme conract").setAction(async(taskArgs, hre) => {
     // 创建合约工厂
     let fundMeFactory = await ethers.getContractFactory("FundMe");
     console.log("Deploying FundMe contract...");
     let fundMe = await fundMeFactory.deploy(100);
     await fundMe.waitForDeployment();
     console.log("FundMe contract deployed to:", fundMe.target);
     console.log("Deploying FundMe contract...done");
 
     // 部署合约并等待合约同步到 Etherscan
     if (hre.network.config.chainId === 11155111 && process.env.ETHER_SCAN_API_KEY9999999999999999) {
         console.log("Waiting for Etherscan to verify the contract...");
         // 验证合约
         await fundMe.deploymentTransaction().wait(5);
         await hre.run("verify:verify", {
             address: fundMe.target,
             constructorArguments: [100],
         });
     } else {
         console.log("verify skipped");
     }
})


module.exports = {}